function demoDrawableDotKinetogram(delay)
% Demonstrate random dot kinetograms, allow visual inspection.

if nargin < 1
    delay = 10;
end

groupName = 'demo';
gridSize = 4;

% access the manager for doing drawing work
dotsTheDrawablesManager.reset();
dm = dotsTheDrawablesManager.theObject;

% create a kinetogram with minimal motion features
clean = dm.newObject('dotsDrawableDotKinetogram');
dm.addObjectToGroup(clean, groupName);
clean.stencilNumber = 1;
clean.diameter = 6;
clean.y = gridSize;
clean.x = -gridSize;
clean.direction = 135;
clean.coherence = 50;

% create a kinetogram with many motion features
messy = dm.newObject('dotsDrawableDotKinetogram');
dm.addObjectToGroup(messy, groupName);
messy.stencilNumber = 2;
messy.diameter = 6;
messy.y = gridSize;
messy.x = gridSize;
messy.direction = 45;
messy.coherence = 50;
messy.isFlickering = false;
messy.isWrapping = false;
messy.isLimitedLifetime = false;
messy.interleaving = 1;
messy.color = [255 64 0];

% create a kinetogram with a *distribution* of motion directions
fancy = dm.newObject('dotsDrawableDotKinetogram');
dm.addObjectToGroup(fancy, groupName);
fancy.stencilNumber = 3;
fancy.diameter = 6;
fancy.y = -gridSize;
fancy.x = -gridSize;
fancy.size = 1;
fancy.density = 30;
fancy.direction = 0:359;
fancy.directionWeights = normpdf(fancy.direction, 225, 30);
fancy.coherence = 100;
fancy.color = [255 255 0];

% create a kinetogram with dots wandering, all together
silly = dm.newObject('dotsDrawableDotKinetogram');
dm.addObjectToGroup(silly, groupName);
silly.stencilNumber = 4;
silly.diameter = 6;
silly.y = -gridSize;
silly.x = gridSize;
silly.size = 5;
silly.smooth = true;
silly.direction = 315;
silly.coherence = 100;
silly.drunkenWalk = 180;
silly.isMovingAsHerd = true;
silly.interleaving = 1;
silly.color = [0 255 255];

% let the manager draw all these kinetograms at once
dm.activateGroup(groupName);

%% animate for the duration given above
try
    % open an OpenGL drawing window
    dm.openScreenWindow;
    
    % draw a single frame and tell the manager to start animating (true)
    dm.mayDrawNextFrame(true);
    
    % let the manager continue animating for a while
    %   this should succeed with local or remote graphics
    dm.runForDuration(delay);
    
    % draw the last frame and tell the manager to stop animating (false)
    dm.mayDrawNextFrame(false);
    
    % close the OpenGL drawing window
    dm.closeScreenWindow;
    
catch err
    dm.closeScreenWindow;
    rethrow(err)
end